package com.hkccommunity.mapper;

import com.hkccommunity.entity.Problem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProblemMapper {

    @Select("select * from problem where `delete` = 0 order by create_time desc limit #{index},#{num};")
    @ResultMap("problemResultMap")
    List<Problem> getProblem(@Param("index") int index,@Param("num") int num );

    @Select("select count(*) from problem where `delete` = 0;")
    int getCount();
    
    @Update("update problem set read_count = read_count +1 where problem_id = #{problemId}")
    int updateReadCount(@Param("problemId") Long problemId);


    @Select("select * from problem where problem_id = #{problemId};")
    @ResultMap("problemResultMap")
    Problem getProblemById(@Param("problemId") Long problemId);

    @Insert("insert into problem values (#{problemId},#{title},#{content},#{img},#{readCount},#{createTime},#{createUser},#{problemLabel},#{delete})")
    int addProblem(Problem problem);

    @Select("select * from problem where title like #{input}  order by create_time desc")
    @ResultMap("problemResultMap")
    List<Problem> getProblemByInput( @Param("input") String input);

}
